require("glon");

VgFJ = {};

function VgFJ:Init()

	if ScrW() > 640 then 
		self:SetSize( ScrW()*0.9, ScrH()*0.9 );
	else
		self:SetSize( 640, 480 );
	end
	self:Center();
	self:SetTitle( "SIS First Joined" );
	self:SetVisible( true );
	self:MakePopup();

	local button = vgui.Create( "DButton", self );
	button:SetText( "Close" );
	button.DoClick = function() self:Close() end
	button:SetSize( 100, 40 );
	button:SetPos( (self:GetWide() - button:GetWide()) / 2, self:GetTall() - button:GetTall() - 10 );

	local HTML = [[
		<html>
		<body style="background-color: blue" >
		<div style="border: solid 20 red; background-color: white;" >

		<h1>Welcome</h1>
		<p>
		<b><u>For first time users</u></b> there will be a book in your invitory telling you HOW to play the game.<br />
		To use the book hit F4 and your invitory will pop up Or bind a key to SIS_inv_toggle .<br />
		Then find the books icon and click it will ask if you want to drop it hit drop.<br />
		Then hit use on the book and it will tell you how.
		</p>

		</div>
		</body>
		</html>
	]];

	local html = vgui.Create( "Html", self );
	html:SetSize( self:GetWide() - 20, self:GetTall() - button:GetTall() - 50 );
	html:SetPos( 10, 30 );
	html:SetHTML( HTML );
end

vgui.Register("Firstjoin", VgFJ, "DFrame");

INV = {}
function INV:Init()
	
	RunConsoleCommand( "query", "3" )
	if ScrW() > 640 then 
		self:SetSize( ScrW()*0.9, ScrH()*0.9 );
	else
		self:SetSize( 640, 480 );
	end
	self:Center();
	self:SetTitle( "Ivitory" );
	self:SetVisible( true );
	self:MakePopup();
	
	local IconList = vgui.Create( "DPanelList", self );
	if ScrW() > 640 then 
		IconList:SetSize( ( ScrW() * 0.9 ) - 40, ( ScrH() * 0.9 ) - 50 );
	else
		IconList:SetSize( 640 - 40, 480 - 40 );
	end
	IconList:EnableVerticalScrollbar( true );
	IconList:EnableHorizontal( true ) ;
	IconList:SetPadding( 4 );
	IconList:Center();
	
	function returned( um )
		Invitory = glon.decode( um:ReadString() );
		local icon = vgui.Create( "SpawnIcon", IconList );
		for k,v in pairs( Invitory ) do
			icon:setModel( v );
			IconList:AddItem( icon );
			icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("gm_spawn", v) end 
		end
	end
	usermessage.hook( "Queryed", returned );
end

vgui.Register("Invitory", INV, "DFrame");

CT = {}
function CT:Init()

	if ScrW() > 640 then 
		self:SetSize( ScrW()*0.9, ScrH()*0.9 );
	else
		self:SetSize( 640, 480 );
	end

	self:Center();
	self:SetTitle( "Change teams?" );
	self:SetVisible( true );
	self:MakePopup();

	local Team1 = vgui.Create( "DImageButton", self );
	Team1:SetPos( 35, 35 );
	Team1:SetImage( "Vgui/Team1.vtf" );
	Team1:SizeToContents();
	Team1.DoClick = function()
		RunConsoleCommand( "set_team_1" );
		self:Close();
	end

	local Team2 = vgui.Create( "DImageButton", self );
	Team2:SetPos( 705, 35 );
	Team2:SetImage( "Vgui/Team2.vtf" );
	Team2:SizeToContents();
	Team2.DoClick = function()
		RunConsoleCommand( "set_team_2" );
		self:Close();
	end

end
vgui.Register("ChangeTeam", CT, "DFrame");